Builder

class Builder @JvmOverloads constructor(title: Text, spacingW: Int = 4, spacingH: Int = spacingW)

Builds a PopupWidget from provided Elements and layout

All popups will come with a title widget Top Center of the layout. The next added element will key off this, or to manually layout off of it, use "title" as the element parent

Author

fzzyhmstrs

Since

0.2.0

Parameters

title

Text - the header title shown at the top of the popup

spacingW

Int, optional - Defines the default horizontal padding between elements. Defaults to 4

spacingH

Int, optional - Defines the default vertical padding between elements. Defaults to using the value from spacingW

Samples

import me.fzzyhmstrs.fzzy_config.screen.LastSelectable
import me.fzzyhmstrs.fzzy_config.screen.widget.PopupWidget
import me.fzzyhmstrs.fzzy_config.screen.widget.internal.CustomButtonWidget
import net.minecraft.client.MinecraftClient
import net.minecraft.client.gui.Element
import net.minecraft.client.gui.ParentElement
import net.minecraft.client.gui.widget.ButtonWidget
import net.minecraft.client.gui.widget.TextWidget
import net.minecraft.text.Text
import net.minecraft.util.Identifier

fun main() { 
   //sampleStart 
   // builds and pushes an example popup widget to a PopupParentElement
// start with the builder. The title will be displayed at the top of the popup like a windows window title
// dy default the horizontal and vertical padding will be 4px; it can be changed here too
val popup = PopupWidget.Builder(Text.translatable("my.cool.popup"))
    //you can add horizontal dividers between content. it automatically justifies to the popup width
    .addDivider()
    //adds a basic element. give it a unique name, and position it
    //this element is positioned below the last added element (the divider in this case), and aligned centered in the popup
    .addElement("text_element", TextWidget(Text.translatable("my.cool.popup.text"), MinecraftClient.getInstance().textRenderer).alignCenter(),
        PopupWidget.Builder.Position.BELOW, PopupWidget.Builder.Position.ALIGN_CENTER)
    //adds a button, this element is below the "text_element" one, and aligned left in the popup bounds
    .addElement("button_1", CustomButtonWidget.builder(Text.translatable("my.cool.popup.button1")) { b-> }.size(50, 44).build(),
        PopupWidget.Builder.Position.BELOW, PopupWidget.Builder.Position.ALIGN_LEFT )
    //a second button, this one is aligned horizontal to the top edge of the "button_1" element,
    //aligns to the right of the widget window and is stretched to meet the closest element to its left ("button_1" in this case)
    .addElement("button_2", CustomButtonWidget.builder(Text.translatable("my.cool.popup.button2")) { b-> }.size(50, 20).build(),
        PopupWidget.Builder.Position.ALIGN_RIGHT_AND_JUSTIFY, PopupWidget.Builder.Position.HORIZONTAL_TO_TOP_EDGE)
    //repeat that with button 3, this time aligned to "button_1" bottom edge
    //this element has a defined parent (button_1), instead of automatically picking the last element
    .addElement("button_3", CustomButtonWidget.builder(Text.translatable("my.cool.popup.button3")) { b-> }.size(50, 20).build(), "button_1",
        PopupWidget.Builder.Position.ALIGN_RIGHT_AND_JUSTIFY, PopupWidget.Builder.Position.HORIZONTAL_TO_BOTTOM_EDGE)
    //there is a special method for adding a "Done" button, this also takes "button_1" as its parent in this case
    //it will automatically align below the parent element and justify across the entire width of the widget
    .addDoneWidget(parent = "button_1")
    //popups can be positioned relative to various contexts.
    //in this case we are using the screen as context, positioning it 100px from the bottom right edge of the screen
    //the context method will bound the popup within the screen if the widget is bigger than 100x100
    .positionX(PopupWidget.Builder.screenContext{ w -> w - 100 })
    .positionY(PopupWidget.Builder.screenContext{ h -> h - 100 })
    //tells the popup to not render a blur behind it
    .noBlur()
    //clicking outside of this widget won't close it automatically (which is default behavior)
    .noCloseOnClick()
    //provide a custom background like so.
    //make sure the texture is a nine-patch texture, and the popup will expect 8 pixels of border and padding before content
    .background(Identifier("my_mod", "my_custom_background"))
    //create the popup!
    .build()

//Last step: push the popup to screen, the PopupWidget API will push the popup onto an open PopupParentElement screen, if any
PopupWidget.push(popup) 
   //sampleEnd
}

Constructors

Link copied to clipboard
constructor(title: Text, spacingW: Int = 4, spacingH: Int = spacingW)

Types

Link copied to clipboard
sealed interface Position

A layout position to apply to a popup element

Link copied to clipboard
Link copied to clipboard

Default position BiFunctions that can be used with positionX and positionY

Functions

Link copied to clipboard

Adds a horizontal divider below the last element, or defined parent

Link copied to clipboard
fun addDoneButton(pressAction: ButtonWidget.PressAction = ButtonWidget.PressAction{ pop() }, parent: String? = null, spacingH: Int = 4): PopupWidget.Builder

Adds a "Done" button below the previously added element, or below the defined parent

Link copied to clipboard
fun addDoneWidget(pressAction: Consumer<CustomButtonWidget> = Consumer { pop() }, parent: String? = null, spacingH: Int = 4): PopupWidget.Builder

Adds a "Done" button below the previously added element, or below the defined parent

Link copied to clipboard
fun <E : Widget> addElement(id: String, element: E, vararg positions: PopupWidget.Builder.Position): PopupWidget.Builder

Adds an element, automatically keyed off the last added element (or "title" if this is the first added element). Uses the default padding.

fun <E : Widget> addElement(id: String, element: E, parent: String, vararg positions: PopupWidget.Builder.Position): PopupWidget.Builder

Adds an element, keyed off a manually defined parent element. Uses the default padding.

Link copied to clipboard
fun <E : Widget> addElementSpacedBoth(id: String, element: E, spacingW: Int, spacingH: Int, vararg positions: PopupWidget.Builder.Position): PopupWidget.Builder

Adds an element with custom vertical and horizontal padding, automatically keyed off the last added element (or "title" if this is the first added element)

fun <E : Widget> addElementSpacedBoth(id: String, element: E, parent: String, spacingW: Int, spacingH: Int, vararg positions: PopupWidget.Builder.Position): PopupWidget.Builder

Adds an element with custom vertical and horizontal padding, keyed off a manually defined parent element.

Link copied to clipboard
fun <E : Widget> addElementSpacedH(id: String, element: E, spacingH: Int, vararg positions: PopupWidget.Builder.Position): PopupWidget.Builder

Adds an element with custom vertical padding, automatically keyed off the last added element (or "title" if this is the first added element)

fun <E : Widget> addElementSpacedH(id: String, element: E, parent: String, spacingH: Int, vararg positions: PopupWidget.Builder.Position): PopupWidget.Builder

Adds an element with custom vertical padding, keyed off a manually defined parent element.

Link copied to clipboard
fun <E : Widget> addElementSpacedW(id: String, element: E, spacingW: Int, vararg positions: PopupWidget.Builder.Position): PopupWidget.Builder

Adds an element with custom horizontal padding, automatically keyed off the last added element (or "title" if this is the first added element)

fun <E : Widget> addElementSpacedW(id: String, element: E, parent: String, spacingW: Int, vararg positions: PopupWidget.Builder.Position): PopupWidget.Builder

Adds an element with custom horizontal padding, keyed off a manually defined parent element.

Link copied to clipboard

Appends a custom narration message to the end of the Popup title.

Link copied to clipboard
fun background(id: Identifier): PopupWidget.Builder

Defines a custom background texture for the popup. Should be a Nine Slice texture

Link copied to clipboard

Builds this builder

Link copied to clipboard

Defines a manual height for the widget. Will override any automatic sizing computations for height

Link copied to clipboard

The widget won't apply a layer of blur behind it when rendering.

Link copied to clipboard

The widget won't close if a click misses its bounding box. Normal behavior closes the popup on a missed click.

Link copied to clipboard

Defines an action to perform when this widget is closed

Link copied to clipboard

Defines the X positioner function for this widget, X being the left edge of the widget, border included.

Link copied to clipboard

Defines the Y positioner function for this widget, Y being the top edge of the widget, border included.

Link copied to clipboard

Defines a manual width for the widget. Will override any automatic sizing computations for width